<?php
// +----------------------------------------------------------------------
// | Author: yaoyihong <510974211@qq.com>
// +----------------------------------------------------------------------
namespace addon\mall\logic;
use app\common\logic\LogicBase;
use \tpfcore\Core;
use think\Db;
use \tpfcore\helpers\StringHelper;

class GoodsPhoto extends LogicBase
{
	public function delGoodsPhoto($data){
		//return [0,"操作成功",url('mall/GoodsPhoto/index')];

		// 删除真实图片
		if(isset($data['id'])){
			$goods_photo = self::getOneObject($data,"url,thumb");

			if($goods_photo){
				if(!empty($goods_photo['url']) && is_file(ROOT_PATH.$goods_photo['url'])){
					@unlink(ROOT_PATH.$goods_photo['url']);
				}
				if(!empty($goods_photo['thumb']) && is_file(ROOT_PATH.$goods_photo['thumb'])){
					@unlink(ROOT_PATH.$goods_photo['thumb']);
				}

				//删除数据
				$result = self::deleteObject($data,true);

				if($result){
					return [0,"操作成功",url('mall/GoodsPhoto/index')];
				}
				return [40045,"操作失败"]; 
			}
			return [40045,"你删除的数据不存在"]; 
		}
		// 删除上传图片
		if(isset($data['url']) && is_file(ROOT_PATH.$data['url'])){
			@unlink(ROOT_PATH.$data['url']);
			return [0,"操作成功",url('mall/GoodsPhoto/index')];
		}
		return [40045,"操作失败"]; 
	}
	public function getGoodsPhoto($data){
		return self::getList($data);
	}
}